package com.qianli.cashmama.product.facade.result;

import com.qianli.cashmama.product.facade.enums.ErrorCodeEnum;

/**
 * 结果集
 * Created by xuyang on 2017/7/20.
 */
public class Result<T>{

    private boolean success = false;

    private Integer code;

    private String msg;

    private T data;

    Result(T data) {
        this.data = data;
    }

    Result(ErrorCodeEnum errorCode) {
        this.success = false;
        this.code = errorCode.getCode();
        this.msg = errorCode.getMsg();
    }

    public static <T> Result<T> buildSuccess(T data) {
        return new Result(data);
    }

    public static <T> Result<T> buildError(ErrorCodeEnum errorCode) {
        return new Result(errorCode);
    }


    public boolean isSuccess() {
        return success;
    }

    public Result setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public Result setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }
}
